

import requests
"""
1.拿到contId
2.拿到videStatusjson 返回的src Url
3.src内容修复
4.下载视频
"""


url = "https://www.pearvideo.com/video_1782794"
contId = url.split("_")[1]

videoStatus = f"https://www.pearvideo.com/videoStatus.jsp?contId={contId}&mrd=0.7867827612983758"
headers = {"Accept":
"application/json, text/javascript, */*; q=0.01",
"Accept-Encoding":
"gzip, deflate, br",
"Accept-Language":
"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Connection":
"keep-alive",
"Cookie":
"aliyungf_tc=5c95784c5847b45d0cd16af0a4211084155cef7bbd49cf040e2c41cfaa36466b; acw_tc=781bad3c16897647419394287e1f9ed2c5b04f256954bbbe5cd8bad3130f2c; JSESSIONID=F34FDEBEDE6081146F11C322D1710095; PEAR_UUID=84983566-b058-4330-a1df-4d0c36c798d6; _uab_collina=168976474232970581785051; Hm_lvt_9707bc8d5f6bba210e7218b8496f076a=1689764743; p_h5_u=51C1F171-4AAC-4E50-86D0-C66967451F4E; Hm_lpvt_9707bc8d5f6bba210e7218b8496f076a=1689764987; _dd_s=logs=1&id=f2909539-4218-4e3c-b9f1-8a96fbebd945&created=1689764742827&expire=1689766050492; SERVERID=a6169b2e0636a71b774d6641c064eb8c|1689765156|1689764741",
"Host":
"www.pearvideo.com",
"Referer":
"https://www.pearvideo.com/video_1782794",
"Sec-Ch-Ua":
'"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
"Sec-Ch-Ua-Mobile":
"?0",
"Sec-Ch-Ua-Platform":
"macOS",
"Sec-Fetch-Dest":
"empty",
"Sec-Fetch-Mode":
"cors",
"Sec-Fetch-Site":
"same-origin",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
}
respon = requests.get(videoStatus,headers=headers)
print(videoStatus)
srcUrl = respon.json()["videoInfo"]["videos"]["srcUrl"]
system = respon.json()["systemTime"]
print(srcUrl)

videoUrl = srcUrl.replace(system,f'cont-{contId}')
print(videoUrl)
# https://video.pearvideo.com/mp4/third/20230522/1689821678891-11298265-183139-hd.mp4
# https://video.pearvideo.com/mp4/third/20230522/cont-1782794-11298265-183139-hd.mp4

# 下载视频
with open("a.mp4",mode="wb") as f:
    f.write(requests.get(videoUrl).content)